package jp.co.neosystem.s2wg.service.dao;

import java.util.List;

import jp.co.neosystem.s2wg.dto.flex.WorkSheet;
import jp.co.neosystem.s2wg.entity.TblTrnWorktimeDetail;
import jp.co.neosystem.s2wg.util.DateUtil;

import org.seasar.extension.jdbc.SqlBatchUpdate;
import org.seasar.extension.jdbc.service.S2AbstractService;

/**
 * TblTrnWorktimeDetail用DAOサービスクラス。
 */
public class WorktimeDetailService extends
		S2AbstractService<TblTrnWorktimeDetail> {
	public int updateBatch(final Integer workId, final List<WorkSheet> workList) {
		final StringBuilder sb = new StringBuilder();
		sb.append("UPDATE TBL_TRN_WORKTIME_DETAIL ");
		sb.append(" SET START_TIME=?,");
		sb.append("     END_TIME=?,");
		sb.append("     WORK_OPTION1=?,");
		sb.append("     WORK_OPTION2=?,");
		sb.append("     COMMENT=?");
		sb.append(" WHERE ");
		sb.append("     WORK_ID=? AND ");
		sb.append("     DAY=?");

		final SqlBatchUpdate batch =
			jdbcManager.updateBatchBySql(sb.toString(), String.class, String.class, Integer.class, Integer.class, String.class, Integer.class, String.class);

		for (final WorkSheet s : workList) {
			batch.params(s.getStartTime(), s.getEndTime(),
					s.getWorkOption1(), s.getWorkOption2(),
					(s.getComment() == null) ? "" : s.getComment(), workId, 
					DateUtil.format(s.getBaseDate(), "dd"));
		}

		return batch.execute().length;
	}
}
